import { getAccessToken, getUserRoles } from './request';

// use localStorage to store the authority info, which might be sent from server in actual project.
export function getAuthority() {
  // return localStorage.getItem('antd-pro-authority') || ['admin', 'user'];
  let authority = getUserRoles();
  const accessToken = getAccessToken();

  // if (accessToken) {
  //   authority = [...authority,'admin'];
  // } else {
  //   authority = ['guest'];
  // }
  if (accessToken && authority) {
    authority = [...authority,'admin'];
    // if (authority.includes('[')) {
    //   authority = JSON.parse(authority);
    // } else {
    //   authority = [JSON.parse(authority)];
    // }
  } else {
    authority = ['guest'];
  }
  return authority;
}

export function setAuthority(authority) {
  return localStorage.setItem('__ywweb_user_roles', JSON.stringify(authority));
}


